from pathlib import Path, PurePath
import os, sys

# Global
STELLARIS_MOD_FOLDER ="/.local/share/Paradox Interactive/Stellaris/mod/"
home_dir = Path.home()
mod_dir = Path(str(home_dir) + STELLARIS_MOD_FOLDER)

# Custom Errors
class CustomError(Exception):
    pass

def main():
    if(not Path.exists(Path(mod_dir))):
        raise CustomError(f'Error: Path {mod_dir} doesnt exist!')

    dirs_of_mods = [x.parts[-1] for x in mod_dir.iterdir() if x.is_dir()]



    for dirname in dirs_of_mods:
        path_dirname = f'{str(mod_dir)}/{dirname}'
        print("Generating .mod dile for " + dirname)
        with open(path_dirname + ".mod", 'w') as f:
            f.write(f'name="{dirname}"\npath="{path_dirname}"')

try:
    main()
except KeyboardInterrupt:
    print("KeyboardInterrupt, exiting...")
    sys.exit(0)


